/**
 * Created by lintao_alex on 2018/8/29
 */


namespace game {
    import GComponent = fairygui.GComponent;
    import BaseWindow = mengdao.BaseWindow;
    import IClass = mengdao.IClass;

    export abstract class ViewWindow<T extends GComponent> extends BaseWindow{
        protected abstract get ViewClass():IClass<T>;//用Class可以让自动生成的代码做编译检查
        protected abstract afterCreate():void;
        private _view:T;
        protected get view():T{
            return this._view;
        }
        protected clickCloseBtn(){
            let that:any = this;
            this.dispatchEventWith(UIEvent.CLOSE, that.constructor)
        }

        /**---------------------- override -----------------------------*/
        __createUI(): void {
            this._view = this.ViewClass['createInstance']();
            let btnClose = this._view.getChild('btnClose');
            if(btnClose) btnClose.addClickListener(this.clickCloseBtn, this);
            this.afterCreate();
        }
        get ui(): GComponent {
            return this._view;
        }
    }
}